# -*- coding: utf-8 -*-
from selenium.common.exceptions import TimeoutException, NoSuchElementException
from pages.base_page import BasePage
from objectsmap.page_locators import Documentation
from pages_exceptions.pages_exceptions import DocumentationException


class DocumentationPage(BasePage):

    TITLE = 'Online Backup & disaster recovery for serious scale IASO'
    LOCATION = 'https://www.iaso.com/documentation'

    def __init__(self, driver):
        super(DocumentationPage, self).__init__(driver, DocumentationPage.LOCATION)

    def is_right_location(self):
        super(DocumentationPage, self).is_right_location(DocumentationPage.TITLE)

    def download_release_note(self):
        try:
            release_element = self._driver.find_element(*Documentation.BTN_RELEASE_NOTE)
            release_element.click()
            download_element = self._driver.find_element(*Documentation.BTN_DOWNLOAD)
            download_element.click()
        except (TimeoutException, NoSuchElementException) as e:
            raise DocumentationException('download failed')
